package com.zy.service.bs.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zy.dao.bs.BbsReplyDao;
import com.zy.entity.enums.StatusEnum;
import com.zy.entity.bs.BbsReply;
import com.zy.pojo.query.bs.BbsReplyQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.service.base.impl.BaseServiceImpl;
import com.zy.service.bs.BbsReplyService;
import com.zy.utils.DateUtil;

@Service("bbsReplyService")
public class BbsReplyServiceImpl extends BaseServiceImpl<BbsReply> implements BbsReplyService {

	@Autowired
	private BbsReplyDao bbsReplyDao;

	@Override
	public PageVo pageBbsReply(BbsReplyQuery bbsReplyQuery, Integer start, Integer limit) {
		return new PageVo(start, limit, this.bbsReplyDao.countBbsReply(bbsReplyQuery), this.bbsReplyDao.listBbsReply(bbsReplyQuery, start, limit));
	}

	@Override
	public void saveBbsReply(BbsReply bbsReply) {
		long time = DateUtil.getTime();
		bbsReply.setCreateTime(time);
		bbsReply.setModifyTime(time);
		bbsReply.setStatus(StatusEnum.NORMAL.getValue());
		this.bbsReplyDao.save(bbsReply);
	}
	
	@Override
	public void updateBbsReply(BbsReply bbsReply) {
		bbsReply.setModifyTime(DateUtil.getTime());
		this.bbsReplyDao.updateByPrimaryKeySelective(bbsReply);
	}

	@Override
	public void removeBbsReply(long id) {
		try {
			this.bbsReplyDao.removeByPrimaryKey(id);
		} catch (Exception e) {
			log.info(e.getMessage(),e);
			BbsReply bbsReply = new BbsReply();
			bbsReply.setId(id);
			bbsReply.setModifyTime(DateUtil.getTime());
			bbsReply.setStatus(StatusEnum.DELETE.getValue());
			this.bbsReplyDao.updateByPrimaryKeySelective(bbsReply);
		}
	}

	@Override
	public void recover(long id) {
		BbsReply bbsReply = new BbsReply();
		bbsReply.setId(id);
		bbsReply.setModifyTime(DateUtil.getTime());
		bbsReply.setStatus(StatusEnum.NORMAL.getValue());
		this.bbsReplyDao.updateByPrimaryKeySelective(bbsReply);
	}

	@Override
	public PageVo appBbsReply(Long customerId, Integer start, Integer limit) {
		return new PageVo(start, limit, this.bbsReplyDao.appCountBbsReply(customerId), this.bbsReplyDao.appListBbsReply(customerId, start, limit));
	}

}
